package com.googlecode.imule.redundant;

import java.io.*;
import java.net.*;

public class UDPConnection {

	public static DatagramSocket socket;
	public static DatagramPacket packet;
	public static InetAddress address;
	public static byte[] buffer;
	public static int port;

	public void receive() throws IOException, SocketException {
		socket = new DatagramSocket();
		buffer = new byte[256];
		packet = new DatagramPacket(buffer, buffer.length);
		socket.send(packet);
	}

	public void send(String message) throws IOException, SocketException {
		socket = new DatagramSocket();
		buffer = message.getBytes();
		address = InetAddress.getLocalHost();
		packet = new DatagramPacket(buffer, buffer.length, address, port);
		socket.send(packet);
		socket.close();
	}

}